#include "comm.hpp"

int main()
{
    // 创建共享内存
    int shmid = CreateShm();
    std::cout << "创建共享内存" << std::endl;
    //sleep(5);
    
    // 挂接到进程地址空间
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);
    std::cout << "进程a 挂接到进程地址空间" << std::endl;
    //sleep(5);
    
    //读数据
    while(1)
    {
        std::cout << "client say@ " << shmaddr << std::endl; //直接访问共享内存
        sleep(1);
    }

    // 断开联系
    shmdt(shmaddr);
    std::cout << "进程a 断开联系" << std::endl;
    //sleep(5);
    // 销毁共享内存
    shmctl(shmid, IPC_RMID, nullptr);

    return 0;
}
